/**
 * TB_DOOR_PRIVILEGEPRIVILEGETYPE
 * 
 *
 *<pre> 
 * 开发公司：苏州东大金点信息技术有限公司
 * 开发人员：唐红锋
 * 邮箱地址：55872655@qq.com
 * 创建时间：2019-09-29 18:53:11
 *</pre>
 */
$(function() {
	privilegeOfPrivilegeType  = new PrivilegeOfPrivilegeType();
	privilegeOfPrivilegeType.init();
	
	formUrl = privilegeOfPrivilegeType.formUrl;
});

(function() {
	//定义常量
	var 	_consts = {
			GRID : "#privilegeOfPrivilegeTypeGrid",// 列表对象
			PAGER : "#privilegeOfPrivilegeTypePager",// 列表分页
			FORM : '#privilegeOfPrivilegeTypeForm',// 表单form
			FORMGET : '#privilegeOfPrivilegeTypeFormGet'// 表单form
			
	};
	/**
	 * TB_DOOR_PRIVILEGEPRIVILEGETYPE 对象
	 * @returns {PrivilegeOfPrivilegeType}
	 */
	PrivilegeOfPrivilegeType = function() {
		//定义属性
	};

	/**
	 * 方法
	 */
	PrivilegeOfPrivilegeType.prototype = {
		consts:	_consts,
		/**
		 * 初始化
		 */
		init : function() {
			if (this.hasInit) // 是否已初始化
				return false;
			this.hasInit = true;
			if ($(this.consts.GRID).length > 0){//列表
				this._initGridList();
			}
				$(document).on('click', 'a.fa-remove', function() {
				// alert("aaaaaaaaaaaaa");
//取消权限：
	// alert($('[name="duallistbox_demo1"]').val());
    // alert($('[name="duallistbox_demo2"]').val());
     var deviceSn="133118548";
     var port="60000";
     var ipaddress="192.168.0.123";
     var caruid="2670463785";
    $.ajax({
    	type: "get",
    	url: "http://192.168.0.187:8025/permissDeleteSingle?deviceSn="
            +deviceSn+"&port="+port+"&ipaddress="+ipaddress
            +"&carId="+caruid, 
          // url:"http://192.168.0.187:8025/geteway",
            jsonp: "callback",
    	    dataType:"json",//注意不是datatype哦
    	    async: false,//使用同步操作，否则init方法执行时setting可能还未被赋值
    	    success: function(data) {
    	            
    	           console.log("res:"+JSON.stringify(data));
    	         if("200"==data.code){
    	        	 alert('sucesss');
    	          
									 //成功返回删除Premission 
									 //begin
								action:__ctx+'/rdp/PrivilegeOfPrivilegeType/privilegeOfPrivilegeType/remove.htm?privilegerecid={id}'
    	         	
    	         	 //end
    	         }else{
    	        	 alert('数据返回失败！')
    	         }
    	  },
    	    error: function(){
                    alert('通信 fail');
          }
    		
    	    
    	    
    	 });






			
			});


			if ($(this.consts.FORM).length > 0){//表单

					alert("eeeeeeeeeeee");
				this._initForm();
				this._initData();
				this._initOffice('e');
			}
			if ($(this.consts.FORMGET).length > 0){// 明细页面office控件初始化
				this._initOffice('r');
			}
		},
		_initOffice : function(_rights){
		},

		/**
		 * 初始列表
		 */
		_initGridList : function() {
			var me = this;
			$(this.consts.GRID).GridList(
					{
						url :  __ctx+'/rdp/PrivilegeOfPrivilegeType/privilegeOfPrivilegeType/listJson.htm',
						pager :this.consts.PAGER,
						colNames: ['PRIVILEGERECID','门标识','控制SEGID','物理消费卡号','控制器编号','控制门号','管理'],
				        colModel: [{
				                 	   name:'privilegerecid',
				                	   index: 'PRIVILEGERECID'

										
				                	 	,hidden:true,key:true
				                	 	}, {
				                 	   name:'doorid',
				                	   index: 'DOORID'

										
				                	 					                	 	}, {
				                 	   name:'controlsegid',
				                	   index: 'CONTROLSEGID'

										
				                	 					                	 	}, {
				                 	   name:'consumerid',
				                	   index: 'CONSUMERID'

										
				                	 					                	 	}, {
				                 	   name:'controllerid',
				                	   index: 'CONTROLLERID'

										
				                	 					                	 	}, {
				                 	   name:'doorno',
				                	   index: 'DOORNO'

										
																													},
													  {
									name : '__manage',
									width : 30,
									sortable:false,
									classes:'rowOps',
									formatter : 'manage',
									formatoptions :[{
										label:'编辑',
										classes:'btn btn-primary fa fa-edit',
										action:__ctx+'/rdp/PrivilegeOfPrivilegeType/privilegeOfPrivilegeType/edit.htm?privilegerecid={id}'
									},{
										label:'删除',
										classes:'btn btn-primary fa fa-remove',
										
										action:__ctx+'/rdp/PrivilegeOfPrivilegeType/privilegeOfPrivilegeType/remove.htm?privilegerecid={id}'

										

									},{
										label:'明细',
										classes:'btn btn-primary fa fa-detail',
										action: __ctx+'/rdp/PrivilegeOfPrivilegeType/privilegeOfPrivilegeType/get.htm?privilegerecid={id}'
									}]
								} ]
	
					});
		},
		
		/**
		 * 初始化表单
		 */
		_initForm : function() {
			
			var me = this, form = $(this.consts.FORM), frm = form.form();
			me.formUrl = new com.lc.form.FormData(form);
			// 触发表单验证
			frm.valid();
			// 处理表单保存
			$(document).on('click', 'a.fa-save', function() {
				var $el = $(this);
				$el.button('loading');
				// office提交
        		OfficePlugin.submit();
				me.formUrl.submit(me._showResponse, $el);
			});

			


		},
		/**
		 * 初始化数据
		 */
		_initData : function(){
			if(!$.isEmpty(frameElement) 
				&& !$.isEmpty(frameElement.dialog) 
				&& !$.isEmpty(frameElement.dialog.params)
				&& !$.isEmpty(frameElement.dialog.params.data)){
				var data = frameElement.dialog.params.data;
				this.formUrl.setData("[name^='m:']", data);
				AttachementControl.initDataTo($("div[name='div_attachment_container']")); //附件初始化
			}else{
				$("[name^='m:']", $(_consts.FORM)).each(function(){
					var data = $(this);
	        		// 单选框特殊处理 
	            	if(data.is('input') && "radio" == data.attr("type")){
			        		var defaultVal = data.attr("defaultVal");
			        		var defaultValue = data.attr("defaultValue");
		            		if(defaultValue=="true"&&defaultVal=="true"){
		            			data.prop("checked", "checked");
		            		}
		        	}
		        });
			}
			
			this.formUrl.validate();
		},
		/**
		 * 表单成功返回信息
		 * 
		 * @param responseText
		 */
		_showResponse : function(responseText) {
			var msg = new com.lc.form.ResultMessage(responseText);
			if (msg.isSuccess()) {
				DialogUtil.confirm(msg.getMessage() + ',是否继续操作',
					function(rtn) {
					if(rtn)
						window.location.reload(true);
					else
						window.location.href = __ctx+'/rdp/PrivilegeOfPrivilegeType/privilegeOfPrivilegeType/list.htm';
					});
			} else {
				DialogUtil.error(msg.getMessage());
			}
		}
	};
})();